﻿var chartArr = [];
//排序并设置权限
function sortAndPower(loginInfo, data) {
    //数组排序
    var sortData = data.sort(function (a, b) {
        if (a.f_sortcode0 < b.f_sortcode0) return -1;
        if (a.f_sortcode0 > b.f_sortcode0) return 1;
        return 0;
    });
    //权限过滤
    var powerData = [];
    $.each(sortData, function (index, itemobj) {
        if (loginInfo.userId == "System") {
            powerData.push(itemobj);
        }
    });
    return powerData;
}
function loadHtml(arr, id, cls, moreeleId, itemUrl, moreUrl, name, icon, prjsta) {
    var htmlStr = "";
    var htmlImg = "";
    var htmlHead = "";
    //申报
    if (cls == "applay") {
        htmlStr += '<div class="block_3 flex-col">';
        htmlStr += '<span class="text_4">申报中的项目</span>';
        htmlStr += '<div class="text-wrapper_1 flex-row justify-between">';
        htmlStr += '<span class="text_5">当前总数：</span>';
        htmlStr += '<span class="text_6 applay"></span>';
        htmlStr += '</div>';
        htmlStr += '<div class="text-wrapper_2 flex-col">';
        htmlStr += '<span class="text_7" id="' + moreeleId + '">查看所有项目</span>';
        htmlStr += '</div>';
        htmlStr += '</div>';
        htmlHead = '<div class="block_4 flex-col"';
        htmlImg = '<img class="thumbnail_3" referrerpolicy="no-referrer" src="img/psxtnorl2if2eg6mp49whubzvhjoszvkd903a2fc8-c4a0-4d8b-92c1-ce8e7dcb2280.png" />';
    }
    //审批
    if (cls == "approval") {
        htmlStr += '<div class="box_1 flex-col">';
        htmlStr += '<span class="text_24">审批中的项目</span>';
        htmlStr += '<div class="text-wrapper_5 flex-row justify-between">';
        htmlStr += '<span class="text_25">当前总数：</span>';
        htmlStr += '<span class="text_26 approval"></span>';
        htmlStr += '</div>';
        htmlStr += '<div class="text-wrapper_6 flex-col">';
        htmlStr += '<span class="text_27" id="' + moreeleId + '">查看所有项目</span>';
        htmlStr += '</div>';
        htmlStr += '</div>';
        htmlHead = '<div class="box_4 flex-col"';
        htmlImg = '<img class="thumbnail_8" referrerpolicy="no-referrer" src="img/psek7z90shk6mfy4k5ojwehkgwu5uc5k4e62a2dce1-269c-42f8-99bf-3442cc598a33.png" />';
    }
    //立项
    if (cls == "lixiang") {
        htmlStr += '<div class="box_6 flex-col">';
        htmlStr += '<span class="text_37">立项中的项目</span>';
        htmlStr += '<div class="text-wrapper_9 flex-row justify-between">';
        htmlStr += '<span class="text_38">当前总数：</span>';
        htmlStr += '<span class="text_39 lixiang"></span>';
        htmlStr += '</div>';
        htmlStr += '<div class="text-wrapper_10 flex-col">';
        htmlStr += '<span class="text_40" id="' + moreeleId + '">查看所有项目</span>';
        htmlStr += '</div>';
        htmlStr += '</div>';
        htmlHead = '<div class="box_7 flex-col"';
        htmlImg = '<img class="thumbnail_10" referrerpolicy="no-referrer" src="img/psgo3v8a175puzih9fh57oejxoyj4mcheyqffc8d287-832e-409f-8c50-a7e3c18c6ad4.png" />';
    }
    //建设
    if (cls == "exec") {
        htmlStr += '<div class="group_12 flex-col">';
        htmlStr += '<span class="text_50">建设中的项目</span>';
        htmlStr += '<div class="text-wrapper_11 flex-row justify-between">';
        htmlStr += '<span class="text_51">当前总数：</span>';
        htmlStr += '<span class="text_52 exec"></span>';
        htmlStr += '</div>';
        htmlStr += '<div class="text-wrapper_12 flex-col">';
        htmlStr += '<span class="text_53" id="' + moreeleId + '">查看所有项目</span>';
        htmlStr += '</div>';
        htmlStr += '</div>';
        htmlHead = '<div class="group_13 flex-col"';
        htmlImg = '<img class="thumbnail_13" referrerpolicy="no-referrer" src="img/psa0fs1g0d4ofilj4sc3isxhrtizm454t7eab93dc-ac9c-4200-a5c8-45ad061a6b2e.png" />';
    }
    //已完成
    if (cls == "over") {
        htmlStr += '<div class="section_5 flex-col">';
        htmlStr += '<span class="text_63">已完成的项目</span>';
        htmlStr += '<div class="text-wrapper_13 flex-row justify-between">';
        htmlStr += '<span class="text_64">当前总数：</span>';
        htmlStr += '<span class="text_65 over"></span>';
        htmlStr += '</div>';
        htmlStr += '<div class="text-wrapper_14 flex-col">';
        htmlStr += '<span class="text_66" id="' + moreeleId + '">查看所有项目</span>';
        htmlStr += '</div>';
        htmlStr += '</div>';
        htmlHead = '<div class="section_6 flex-col"';
        htmlImg = '<img class="thumbnail_3" referrerpolicy="no-referrer" src="img/psggjd5w9jyit53vbhf6jqxtov2t5tzws9e3e7f052-eb1d-4b9c-819d-d872c3361e41.png" />';
    }

    for (var j = 0; j < arr.length; j++) {
        //if (j > 4) continue;
        var item = arr[j];
        htmlStr += htmlHead + 'id="' + item.OID + 'item" onclick="OpenIt(\'/WF/Comm/RefFunc/En.htm?FK_Flow=001&EnName=BP.PM.Data.ND1RptExt&OID=' + item.OID + '\')" >';
        htmlStr += '<span class="text_8">' + item.PrjName + '</span>';
        htmlStr += '<span class="text_9">' + item.XMLXT + '</span>';
        htmlStr += '<div class="group_3 flex-row">';
        htmlStr += htmlImg;
        htmlStr += '<span class="text_10">' + item.LianXiRen + '</span>';
        htmlStr += '<span class="text_11">' + item.RDT + '</span>';
        htmlStr += '</div>';
        htmlStr += '    </div>';
    }
    $("#" + id).append(htmlStr);
    $("#" + moreeleId).on('click', function () {
        window.top.vm.openTab("项目总览", "/WF/Comm/Batch.htm?EnsName=BP.PM.Data.ND1Rpts&PrjSta=" + prjsta);
    });
}

function OpenIt(url) {
    window.open(url);
}

function setSpanNum(arr) {
    var prjobj = arr.filter((item) => item.PrjSta == 1)[0];
    if (prjobj != undefined) {
        $('.applay').html(prjobj.Num + "项");
    } else {
        $('.applay').html(0);
    }
    prjobj = arr.filter((item) => item.PrjSta == 2)[0];
    if (prjobj != undefined) {
        $('.approval').html(prjobj.Num + "项");
    } else {
        $('.approval').html(0);
    }
    prjobj = arr.filter((item) => item.PrjSta == 3)[0];
    if (prjobj != undefined) {
        $('.lixiang').html(prjobj.Num + "项");
    } else {
        $('.lixiang').html(0);
    }
    prjobj = arr.filter((item) => item.PrjSta == 4)[0];
    if (prjobj != undefined) {
        $('.exec').html(prjobj.Num + "项");
    } else {
        $('.exec').html(0);
    }
    prjobj = arr.filter((item) => item.PrjSta == 5)[0];
    if (prjobj != undefined) {
        $('.over').html(prjobj.Num + "项");
    } else {
        $('.over').html(0);
    }
}
function loadDesktop() {
    $("#ApplayList,#ApprovalList,#LiXiangList,#ExecList,#OverList,#noticeList,#waringList").html("");

    var handler = new HttpHandler("BP.PM.Handler.AnalysisHandler");
    var res = handler.DoMethodReturnString("InitHomeData");
    res = eval('(' + res + ')');

    if (res.Success && res.Data) {
        res = res.Data;
    }

    $("#searchmorebtn").on('click', function () {
        window.top.vm.openTab("项目总览", "/WF/Comm/Batch.htm?EnsName=BP.PM.Data.ND1Rpts");
    });

    $("#searchbtn").on('click', function () {
        window.top.vm.openTab("项目总览", "/WF/Comm/Batch.htm?EnsName=BP.PM.Data.ND1Rpts&Key=" + $('#keyWords').val());
    });

    //申报中
    loadHtml(res.ApplayData, 'ApplayList', 'applay', 'applaymore', "itemUrl", "moreUrl", "申报中", "layui-icon-notice", 1);

    //审批中
    loadHtml(res.ApprovalData, 'ApprovalList', 'approval', 'approvalmore', "itemUrl", "moreUrl", "审批中", "layui-icon-username", 2);
    //立项中
    loadHtml(res.LiXiangData, 'LiXiangList', 'lixiang', 'lixiangmore', "itemUrl", "moreUrl", "立项中", "layui-icon-form", 3);
    //建设中
    loadHtml(res.ExecData, 'ExecList', 'exec', 'execmore', "itemUrl", "moreUrl", "建设中", "layui-icon-location", 4);
    //已完工
    loadHtml(res.OverData, 'OverList', 'over', 'overmore', "itemUrl", "moreUrl", "已完工", "layui-icon-auz", 5);

    //公告通知
    var htmlStr = "";
    var noticeData = res.NoticeData;
    for (var i = 0; i < noticeData.length; i++) {
        var _title = (noticeData[i].Title.length > 20 ? noticeData[i].Title.substr(0, 20) + "..." : noticeData[i].Title)
        var _time = (noticeData[i].ReleaseTime.length > 10 ? noticeData[i].ReleaseTime.substr(0, 10) : noticeData[i].ReleaseTime)
        htmlStr += '<div class="box_14 flex-row" onclick=OpenTabIt(\'' + noticeData[i].Title + '\',\'../App/zcfgcx/Utility/ListContent.html?id=' + noticeData[i].OID + '&enName=BP.PM.Policy.Notice\')>';
        htmlStr += '<div class="group_25 flex-col"></div>';
        htmlStr += '<span class="text_83" >' + _title + '</span>';
        htmlStr += '<span class="text_84">' + _time + '</span>';
        htmlStr += '</div>';
    }

    $("#noticeList").append(htmlStr);
    $(".btnmore").on('click', function () {
        window.top.vm.openTab("公告通知", "home.htm");
    });

    //预警信息
    htmlStr = "";
    var warningData = res.WarningData;
    for (var i = 0; i < warningData.length; i++) {
        var _title = (warningData[i].Title.length > 20 ? warningData[i].Title.substr(0, 20) + "..." : warningData[i].Title)
        var _time = (warningData[i].ReleaseTime.length > 10 ? warningData[i].ReleaseTime.substr(0, 10) : warningData[i].ReleaseTime)
        htmlStr += '<div class="group_36 flex-row" onclick=OpenTabIt(\'' + warningData[i].Title + '\',\'../App/zcfgcx/Utility/ListContent.html?id=' + warningData[i].OID + '&enName=BP.PM.Perform.SysWarning\')>';
        htmlStr += '<div class="box_34 flex-col"></div>';
        htmlStr += '<span class="text_109">' + _title + '</span>';
        htmlStr += '<span class="text_110">' + _time + '</span>';
        htmlStr += '</div>';
    }

    $("#waringList").append(htmlStr);
    $("#btnmorewarning").on('click', function () {
        window.top.vm.openTab("预警信息", "../App/zcfgcx/Utility/warnindex.htm?enName=BP.PM.Perform.SysWarning");
    });

    htmlStr = "";
    setSpanNum(res.GroupData);
}
function OpenTabIt(name, url) {
    window.top.vm.openTab(name, url)
}
function winHint() {
    try {


        var handler = new HttpHandler("BP.PM.Handler.AnalysisHandler");
        var res = handler.DoMethodReturnString("GetInfosData");
        res = eval('(' + res + ')');

        if (res.Success && res.Data) {
            res = res.Data;

            if (res.length == 0) {
                return;
            }
            var htmlStr = "";

            if (res.SysWarns > 0) {
                var _title = "预警信息：[" + res.SysWarns + "]条";
                var _time = res.CurDate
                htmlStr += '<div class="layui-row content-self">';
                htmlStr += '<div class="layui-col-md8"><i style="color: #1E9FFF;" class="layui-icon layui-icon-speaker layui-icon-self"></i><a href=\'javascript:window.top.vm.openTab("预警信息", "../App/zcfgcx/Utility/warnindex.htm?enName=BP.PM.Perform.SysWarning");\' style="cursor:pointer !important;color:black;">' + _title;
                htmlStr += '</a></div>';
                htmlStr += '<div class="layui-col-md4" style="text-align:right;">' + _time;
                htmlStr += '</div>';
                htmlStr += '</div>';
            }
            if (res.SysHastens > 0) {
                var _title = "催办信息：[" + res.SysHastens + "]条";
                var _time = res.CurDate
                htmlStr += '<div class="layui-row content-self">';
                htmlStr += '<div class="layui-col-md8"><i style="color: #1E9FFF;" class="layui-icon layui-icon-speaker layui-icon-self"></i><a href=\'javascript:window.top.vm.openTab("催办信息", "../App/zcfgcx/Utility/hastenindex.htm?enName=BP.PM.Perform.SysHasten");\' style="cursor:pointer !important;color:black;">' + _title;
                htmlStr += '</a></div>';
                htmlStr += '<div class="layui-col-md4" style="text-align:right;">' + _time;
                htmlStr += '</div>';
                htmlStr += '</div>';
            }
            if (res.TodoLists > 0) {
                var _title = "项目待办：[" + res.TodoLists + "]条";
                var _time = res.CurDate
                htmlStr += '<div class="layui-row content-self">';
                htmlStr += '<div class="layui-col-md8"><i style="color: #1E9FFF;" class="layui-icon layui-icon-speaker layui-icon-self"></i><a href=\'javascript:window.top.vm.openTab("项目待办", "../App/F001/Todolist.htm");\' style="cursor:pointer !important;color:black;">' + _title;
                htmlStr += '</a></div>';
                htmlStr += '<div class="layui-col-md4" style="text-align:right;">' + _time;
                htmlStr += '</div>';
                htmlStr += '</div>';
            }

            if (htmlStr == "")
                return;

            layer.open({
                type: 1
                , offset: 'rb'
                , id: 'layerDemo' //防止重复弹出
                , content: '<div class="layui-card-body layui-text" id="noticeList">' + htmlStr + '</div>'
                //, btn: '关闭'
                , btnAlign: 'c'
                , area: ['350px', '300px']
                , moveType: 1
                , moveOut: false
                , title: '消息提示'
                , shade: 0 //不显示遮罩
                , yes: function () {
                    layer.closeAll();
                }
                , time: 30 * 1000
            });
        }
    } catch (e) {
        alert(e);
        window.clearInterval(hintTimer);
    }
}
var hintTimer;
$(function () {
    loadDesktop();

    winHint();

    hintTimer = window.setInterval(function () {
        winHint();
    }, 1000 * 60 * 10);
})
